package com.css.fxfzypg.modules.maps.controller;

import com.css.fxfzypg.base.response.RestResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.locationtech.jts.algorithm.distance.DistanceToPoint;
import org.locationtech.jts.algorithm.distance.PointPairDistance;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

import java.util.Map;

/**
 * @author zyt
 * @create 2023-2-28
 * 空间数据计算
 */
@RestController
@RequestMapping("/geomCompute")
@Slf4j
public class GeomComputeController {

    /**
     * 计算点在线的垂线
     * 计算点在线上的垂足
     */
    @GetMapping("/getFootPoint")
    public RestResponse getFootPoint() {

        RestResponse restResponse = null;
        try{
            PointPairDistance pointPairDistance = new PointPairDistance();

            WKTReader wktReader = new WKTReader();
            //线L1
            LineString lineString =  (LineString) wktReader.read("LINESTRING (0 0, 1 1)");
            //点p1
            Point point = (Point) wktReader.read("POINT (3 2)");
            DistanceToPoint.computeDistance(lineString, point.getCoordinate(),pointPairDistance);
            String result = pointPairDistance.toString();

            System.out.println(result);
            restResponse = RestResponse.succeed(result);
        }catch (Exception e){
            log.error("查询数据失败!",e);
            restResponse = RestResponse.fail("查询数据失败");
        }
        return restResponse;
    }
}
